<template>
  <el-dialog
    title="移动组织"
    :visible.sync="myorganizationMoveDialog"
    width="20%"
    @open="organizationMoveDialogOpen"
  >
    <div  ref="wrapper"  style="height:350px;border:1px solid #f1f1f1" class="tfscrollbarstyle">
      <el-tree
        class="filter-tree"
        empty-text="没有数据"
        node-key="id"
        :expand-on-click-node="false"
        :data="data"
        :props="defaultProps"
        :highlight-current="true"
        :default-expand-all="true"
        @node-click="nodeClick"
        ref="organizationMoveTree">
      </el-tree>
    </div>
    <span slot="footer" class="dialog-footer">
        <el-button @click="myorganizationMoveDialog = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitOrganizationMoveForm('moveOrganizationForm')" size="mini">确 定</el-button>
      </span>
  </el-dialog>
</template>
<style>

</style>
<script>
  import { yfuPost } from '@/utils/request.js'
  import { yfuSuccessToast, yfuErrorToast } from '@/utils/yfuMessage.js'
  import {moveOrganizationRemote} from '@/view/api/organization.js'
  export default {
    props: ['treeApi'],
    methods: {
      getData () {
        let cThis = this
        yfuPost(process.env.BASE_API, this.treeApi.url, {}, function (data) {
          cThis.data = data
        })
      },
      submitOrganizationMoveForm (formName) {
        let cThis = this
        if (this.toOrganizatoinId > 0) {
          this.selectedRow.parentId = this.toOrganizatoinId
          yfuPost(process.env.BASE_API, moveOrganizationRemote.url, this.selectedRow, function (data) {
            // 关闭dialog
            cThis.myorganizationMoveDialog = false
            yfuSuccessToast('保存成功')
            cThis.$emit('on-refresh-change')
          })
        } else {
          yfuErrorToast('必须选中组织')
        }
      },
      organizationMoveDialogOpen () {
        this.getData()
      },
      nodeClick (data, node, item) {
        this.toOrganizatoinId = node.data.id
      },
      openMoveOrganizationDialog (row) {
        this.selectedRow = row
        this.myorganizationMoveDialog = true
      }
    },
    data () {
      return {
        selectedRow: {},
        toOrganizatoinId: 0,
        moveOrganizationForm: {
        },
        myorganizationMoveDialog: false,
        data: [],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      }
    }
  }
</script>
